package com.xinqi.modules.sys.log.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.sys.log.domain.OperatorLogEntity;
import com.xinqi.modules.sys.log.dto.rsp.OperatorLogResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.Map;

/**
 * 操作日志记录转换
 *
 * @author: yyzhen
 * @date: 2023/08/23
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class OperatorLogConvert {

    @Mappings({@Mapping(expression = "java(map.get(\"title\").toString())", target = "title"),
        @Mapping(expression = "java(map.get(\"businessType\").toString())", target = "businessType"),
        @Mapping(expression = "java(map.get(\"method\").toString())", target = "method"),
        @Mapping(expression = "java(map.get(\"requestMethod\").toString())", target = "requestMethod"),
        @Mapping(expression = "java(map.get(\"operatorType\").toString())", target = "operatorType"),
        @Mapping(expression = "java(Long.parseLong(map.get(\"operatorId\").toString()))", target = "operatorId"),
        @Mapping(expression = "java(map.get(\"operatorUrl\").toString())", target = "operatorUrl"),
        @Mapping(expression = "java(map.get(\"operatorIp\").toString())", target = "operatorIp"),
        @Mapping(expression = "java(map.get(\"operatorLocation\").toString())", target = "operatorLocation"),
        @Mapping(expression = "java(map.get(\"operatorParam\").toString())", target = "operatorParam"),
        @Mapping(expression = "java(map.get(\"jsonResult\").toString())", target = "jsonResult"),
        @Mapping(expression = "java(map.get(\"status\").toString())", target = "status"),
        @Mapping(expression = "java(map.get(\"errorMsg\").toString())", target = "errorMsg")})
    public abstract OperatorLogEntity create(Map<String, Object> map);

    public abstract OperatorLogResultDTO convert(OperatorLogEntity s);

}
